package com.example.interviewdemo.reentrantLock;

/**
 * @program my-project-model
 * @description:
 * @author: lee
 * @create: 2023/01/04 09:54
 */
public class ReentrantLockMain {
    private ReentrantLock reentrantLock = new ReentrantLock();
//ReentrantLock

    public static void main(String[] args) {
        ReentrantLockMain reentrantLockMain = new ReentrantLockMain();
        reentrantLockMain.methodA();
    }

    public void methodA() {

        try {
            reentrantLock.lock();
            System.out.println("methodA方法被调用");
            methodB();


        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            reentrantLock.unLock();
        }

    }

    public void methodB() {

        try {
            reentrantLock.lock();
            System.out.println("methodB方法被调用");


        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            reentrantLock.unLock();
        }

    }
}
